<link rel="stylesheet" href="js/lay-module/eleTree/eleTree.css">
<div class="dialog-wrap">
    <div class="fold-modular" lay-filter="foldModular"></div>
</div>


<script type="text/html" id="folderTemp">
    <div class="dialog-wrap">
        <form class="layui-form">
            <div class="layui-row">
                <div class="layui-form-item">
                    <label class="layui-form-label">收藏夹名<span class="color-red">*</span></label>
                    <div class="layui-input-block">
                        <input type="text" name="personalId" lay-verify="required" placeholder="" autocomplete="off" class="layui-input" value="{{d.name}}">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">共享</label>
                    <div class="layui-input-block">
                        <div class="share-group clearfix">
                            <div class="layui-input-inline">
                                <select name="city">
                                    <option value=""></option>
                                    <option value="0">北京</option>
                                    <option value="1">上海</option>
                                    <option value="2">广州</option>
                                    <option value="3">深圳</option>
                                    <option value="4">杭州</option>
                                </select>
                            </div>
                            <div class="layui-input-inline">
                                <a href="javascript:;" class="layui-btn layui-btn-xs layui-btn-danger">删除</a>
                            </div>
                        </div>
                        <div>
                            <a href="javascript:;" class="add-share-btn color-blue">添加共享</a>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
</script>
<script>
    layui.use(['layer', 'laytpl', 'eleTree', 'utils'], function () {
        var $ = layui.jquery,
            layer = layui.layer,
            laytpl = layui.laytpl,
            eleTree = layui.eleTree,
            utils = layui.utils;

        var foldTreeEl = eleTree.render({
            elem: '.fold-modular',
            url: 'api/talent/folder.json',
            showLine: true,
            request: {
                name: "name",
                key: "id",
                children: "children",
                isLeaf: "isleaf"
            },
            response: {
                statusName: "code",
                statusCode: 200,
                dataName: "data"
            },
            contextmenuList: [
                {
                    eventName: "foldEdit",
                    text: "编辑收藏夹"
                },
                {
                    eventName: "foldAdd",
                    text: "增加子收藏夹"
                },
                {
                    eventName: "foldDel",
                    text: "删除收藏夹"
                }
            ]
        });

        eleTree.on("nodeFoldEdit(foldModular)", function (d) {
            var _data = d.data;

            utils.Ajax({
                url: 'api/talent/folderEdit.json',
                dataType: 'json',
                type: 'post',
                data: {id: _data.id},
                success: function (response) {
                    laytpl($('#folderTemp').html()).render(response.data, function(html){
                        layer.open({
                            title: '收藏夹',
                            area: ['580px', '300px'],
                            type: 1,
                            shade: 0,
                            content: html,
                            btn: ['保存', '取消'],
                            btnAlign: 'c',
                            yes: function(index, layero){
                                var rr = {
                                    "count": "10",
                                    "id": 787,
                                    "isleaf": 1,
                                    "name": "34423432324",
                                    "pid": "801",
                                    "type": "folders"
                                }
                                foldTreeEl.updateKeySelf(_data.id, rr);
                                layer.close(index);
                            },
                        });

                    });

                }
            });

        })

        eleTree.on("nodeFoldDel(foldModular)", function (d) {
            var _data = d.data;
            layer.alert('确定要删除吗？', {title: '收藏夹', btn: ['确定'], shade: 0}, function (index) {
                utils.Ajax({
                    url: 'api/talent/folder.json',
                    dataType: 'json',
                    type: 'post',
                    data: {id: _data.id},
                    success: function (response) {
                        layer.msg(response.message, {time: 1000}, function () {
                            layer.close(index);
                        });
                        foldTreeEl.remove(_data.id)
                    }
                });
            });
        })

    })
</script>
